<?php
/*
<Model Information> 
Author: Naseer Ahmad
Date: 19-10-2011
Last Updated on: 
*/


class adManagerModel extends appModel 
{
	var $name = 'adManagerModel';

	function getAdData($criteria, $limit){
		$ads = $this -> _getArrayData("adsInfo", "*", $criteria.$limit);
		$tRec = $this -> _getSingleData("adsInfo", "COUNT(*)", $criteria);
		
		for($i=0; $i<count($ads); $i++){
			$img = $this -> _getSingleData("adImages", "imageName", "adID=".$ads[$i]['adID']." limit 1");
			$usInfo = $this -> _getRowData("usersInfo", "userName, userEmail", "userID=".$ads[$i]['userID']);
			$ads[$i]['adImg'] = $img;
			$ads[$i]['adUserName'] = $usInfo['userName'];
			$ads[$i]['adUserEmail'] = $usInfo['userEmail'];
		}
		
		
		$adsReturn['data']=$ads;
		$adsReturn['tRec']=$tRec;
		
		return $adsReturn;
	}
	
	function getStatistics(){
		$stat=array();
		$stat['All'] = $this -> _getSingleData("adsInfo", "COUNT(*)");
		$stat['Approved'] = $this -> _getSingleData("adsInfo", "COUNT(*)", "status='Approved'");
		$stat['Rejected'] = $this -> _getSingleData("adsInfo", "COUNT(*)", "status='Rejected'");
		$stat['Pending'] = $this -> _getSingleData("adsInfo", "COUNT(*)", "status='Pending'");
		$stat['Featured'] = $this -> _getSingleData("adsInfo", "COUNT(*)", "isFeatured=1");
		return $stat;
	}

}

?>